package com.yms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.yms.mapper.MarriedPersonMapper;
import com.yms.pojo.MarriedPerson;
import com.yms.pojo.PageResult;
import com.yms.pojo.Result;
import com.yms.service.IMarriedPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2020-03-20
 */
@Service
public class MarriedPersonServiceImpl extends ServiceImpl<MarriedPersonMapper, MarriedPerson> implements IMarriedPersonService {

    @Autowired
    private MarriedPersonMapper marriedPersonMapper;


    @Override
    public PageResult<MarriedPerson> selectMarried(MarriedPerson searchCondition) {
        Page<MarriedPerson> personPage = new Page<>();
        IPage<MarriedPerson> marriedPersonIPage = marriedPersonMapper.selectMorePage(personPage,searchCondition);
        PageResult<MarriedPerson> result = new PageResult<>();
        result.setTotal(marriedPersonIPage.getTotal());
        result.setRows(marriedPersonIPage.getRecords());
        return result;
    }

    @Override
    public MarriedPerson personLogin(MarriedPerson marriedPerson) {
        MarriedPerson marriedPerson1 = marriedPersonMapper.selectOne(new QueryWrapper<MarriedPerson>()
        .eq("phone",marriedPerson.getPhone())
                .eq("ppwd",marriedPerson.getPpwd())
        );
        return marriedPerson;
    }

    @Override
    public Result reg(MarriedPerson marriedPerson) {
        marriedPerson.setRegdate(LocalDateTime.now());
        marriedPerson.setStatus("1");
        int insert = marriedPersonMapper.insert(marriedPerson);
        return new Result(insert>0?true:false,insert>0?"注册成功":"注册失败");
    }
}
